// const baseTarget = 'http://192.168.3.67:9999'
// const baseTarget = 'http://192.168.3.72:9999'
// const baseTarget = 'http://47.111.3.41:9999'
const baseTarget = 'https://www.xymsdp.top'


export default (param) => {
  param.url = baseTarget + param.url
  // const token = uni.getStorageSync('token');

  if(!param.header){
	param.header = {
		'content-type': 'application/x-www-form-urlencoded',
		// 'Authorization': token
	}
  }
  // 加载中
  uni.showLoading({
    title: '正在努力加载...',
	mask: true
  });

  return new Promise((resolve, reject) => {
    uni.request({
      ...param,
      success (res) {
		const {code, header} = res.data
		// uni.setStorageSync('token', header)
		if(code === 401 || code === 403){  // 未登录的情况
			uni.showToast({
				title: '登录状态已过期',
				icon: 'none'
			})
			uni.navigateTo({
				url: '/pages/login/index'
			})
		}
        resolve(res.data)
      },
      fail (err) {
		uni.showToast({
			title: '请求失败！',
			icon: 'none'
		})
        reject(err)
      },
      complete () {
        uni.hideLoading();
      }
    });
  })
}